﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            var uid = textBox1.Text;
            var pwd = textBox2.Text;

            var usr = users.Where(x => x.Key == uid && x.Value == pwd).Select(x => new { key = x.Key, value = x.Value }).FirstOrDefault();

            if (!string.IsNullOrEmpty(uid) && !string.IsNullOrEmpty(pwd) && usr != null)
            {
                MessageBox.Show("登录成功!");
                MainForm mainForm = new MainForm();
                this.Hide();
                mainForm.Show();
            }
            else if (string.IsNullOrEmpty(uid) && string.IsNullOrEmpty(pwd))
            {
                MessageBox.Show("用户名和密码不能为空！", "提示");
            }
            else if ((string.IsNullOrEmpty(uid) && !string.IsNullOrEmpty(pwd)) || (!string.IsNullOrEmpty(uid) && string.IsNullOrEmpty(pwd)))
            {
                MessageBox.Show("用户名或密码不能为空！", "提示");
            }
            else
            {
                MessageBox.Show("用户名或密码错误!", "提示");
            }
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            RegisterForm registerForm = new RegisterForm();
            registerForm.Show();
        }
        /// <summary>
        /// 存储用户名及密码
        /// </summary>
        public static Dictionary<string, string> users = new Dictionary<string, string>();
        private void Form1_Load(object sender, EventArgs e)
        {
            users.Add("sa", "123");
        }
    }
}
